package com.baizhi.service.impl;

import com.baizhi.dao.BannerDAO;
import com.baizhi.entity.Banner;
import com.baizhi.service.BannerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BannerServiceImpl implements BannerService {
    @Autowired
    private BannerDAO bannerDAO;

    @Override
    public PageInfo<Banner> selectAll(Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<Banner> banners = bannerDAO.selectAll();
        PageInfo<Banner> pageInfo = new PageInfo<>(banners);
        return pageInfo;
    }

    @Override
    public Boolean updateBanner(Banner banner) {
        Boolean a = null;
        try{
            System.out.println("banner = " + banner);
            bannerDAO.updateBanner(banner);
            a = true;
        }catch(Exception e){
            e.printStackTrace();
            a = false;
        }
        return a;
    }

    @Override
    public Boolean insertBanner(Banner banner) {
        Boolean a = null;
        try{
            bannerDAO.insertBanner(banner);
            a = true;
        }catch(Exception e){
            a = false;
        }
        return a;
    }

    @Override
    public Banner selectOne(Integer id) {
        Banner banner = bannerDAO.selectOne(id);
        return banner;
    }

    @Override
    public Boolean updateStatus(Banner banner) {
        Boolean a = null;
        try{
            banner.setState(2);
            bannerDAO.updateBanner(banner);
            a = true;
        }catch(Exception e){
            a = false;
        }
        return a;
    }


}
